package cms.manage.template.impl;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import cms.bean.like.TopicLikeEntity;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Component;

import cms.bean.like.TopicLike;
import cms.bean.template.Forum;
import cms.bean.user.AccessUser;
import cms.service.like.LikeService;
import cms.manage.LikeManage;

/**
 * 点赞 -- 模板方法实现
 *
 */
@Component
public class LikeTemplateManage extends BaseTemplateManage{
	@Resource LikeService likeService; 
	@Resource LikeManage likeManage;
	
	/**
	 * 话题点赞总数  -- 实体对象
	 * @param forum 版块对象
	 * @param parameter 参数
	 */
	public Long likeCountEntityBean(Forum forum, Map<String,Object> parameter, Map<String,Object> runtimeParameter){
		Long topicId = MapUtils.getLong(parameter,"topicId");
		if(topicId != null && topicId >0L){
			//根据话题Id查询被收藏数量
			return likeManage.queryCacheFindLikeCountByTopicId(topicId);
		}else{
			return 0L;
		}
	}
	
	/**
	 * 用户是否已经点赞该话题  -- 实体对象
	 * @param forum 版块对象
	 * @param parameter 参数
	 */
	public Boolean alreadyLikedEntityBean(Forum forum, Map<String,Object> parameter, Map<String,Object> runtimeParameter){
		Long topicId = MapUtils.getLong(parameter,"topicId");
		if(topicId != null && topicId>0L){
			AccessUser accessUser = getAccessUser(runtimeParameter);
			if(accessUser!=null) {
				String topicLikeId = likeManage.createTopicLikeId(topicId, accessUser.getUserId());
				TopicLikeEntity topicLike = likeManage.queryCacheFindTopicLikeById(topicLikeId);
				if (topicLike != null) {
					return true;
				}
			}
		}
		return false;
	}
	
	
	/**
	 * 给话题点赞
	 * @param forum
	 */
	public Map<String,Object> addLikeCollection(Forum forum, Map<String,Object> parameter, Map<String,Object> runtimeParameter){
		Map<String,Object> value = new HashMap<String,Object>();
		
		return value;
	}
}
